home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / Found / FWStream / Sources / FWStrmF.cpp < prev    next >
Encoding:
Text File  |  1995-11-08  |  24.6 KB  |  716 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWStrmF.cpp
  4. //    Release Version:    $ 1.0d11 $
  5. //
  6. //    Copyright:    (c) 1993, 1995 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWFound.hpp"
  11.  
  12. #ifndef FWSTRMF_H
  13. #include "FWStrmF.h"
  14. #endif
  15.  
  16. #ifndef FWPRISTR_H
  17. #include "FWPriStr.h"
  18. #endif
  19.  
  20. #ifndef FWEXCDEF_H
  21. #include "FWExcDef.h"
  22. #endif
  23.  
  24. #if FW_LIB_EXPORT_PRAGMAS
  25. #pragma lib_export on
  26. #endif
  27.  
  28. #pragma segment FWStream
  29.  
  30. //========================================================================================
  31. //    CLASS FW_CReadableStreamFormatter
  32. //========================================================================================
  33.  
  34. //----------------------------------------------------------------------------------------
  35. // FW_CReadableStreamFormatter::FW_CReadableStreamFormatter
  36. //----------------------------------------------------------------------------------------
  37.  
  38. FW_CReadableStreamFormatter::FW_CReadableStreamFormatter()
  39. {
  40. }
  41.  
  42. //----------------------------------------------------------------------------------------
  43. // FW_CReadableStreamFormatter::~FW_CReadableStreamFormatter
  44. //----------------------------------------------------------------------------------------
  45.  
  46. FW_CReadableStreamFormatter::~FW_CReadableStreamFormatter()
  47. {
  48. }
  49.  
  50. //----------------------------------------------------------------------------------------
  51. // FW_CReadableStreamFormatter::ReadBytes
  52. //----------------------------------------------------------------------------------------
  53.  
  54. void FW_CReadableStreamFormatter::ReadBytes(FW_CSink& sink,
  55.                                             void* destination,
  56.                                             long count)
  57. {
  58.     Identity(sink, destination, count, 1);
  59. }
  60.  
  61. //----------------------------------------------------------------------------------------
  62. // FW_CReadableStreamFormatter::ReadChars
  63. //----------------------------------------------------------------------------------------
  64.  
  65. void FW_CReadableStreamFormatter::ReadChars(FW_CSink& sink,
  66.                                             char* destination,
  67.                                             long count)
  68. {
  69.     Identity(sink, destination, count, sizeof(char));
  70. }
  71.     
  72. //----------------------------------------------------------------------------------------
  73. // FW_CReadableStreamFormatter::ReadSignedChars
  74. //----------------------------------------------------------------------------------------
  75.  
  76. void FW_CReadableStreamFormatter::ReadSignedChars(FW_CSink& sink,
  77.                                                   signed char* destination,
  78.                                                   long count)
  79. {
  80.     Identity(sink, destination, count, sizeof(signed char));
  81. }
  82.  
  83. //----------------------------------------------------------------------------------------
  84. // FW_CReadableStreamFormatter::ReadUnsignedChars
  85. //----------------------------------------------------------------------------------------
  86.  
  87. void FW_CReadableStreamFormatter::ReadUnsignedChars(FW_CSink& sink,
  88.                                                     unsigned char* destination,
  89.                                                     long count)
  90. {
  91.     Identity(sink, destination, count, sizeof(unsigned char));
  92. }
  93.  
  94. //----------------------------------------------------------------------------------------
  95. // FW_CReadableStreamFormatter::ReadNullTerminatedString
  96. //----------------------------------------------------------------------------------------
  97.  
  98. void FW_CReadableStreamFormatter::ReadNullTerminatedString(FW_CSink& sink,
  99.                                                            char* destination)
  100. {
  101.     long totalBytesCopied = 0;
  102.     long availableReadBytes;
  103.     const char * source = (const char *)sink.ReadPeek(availableReadBytes);
  104.     FW_Boolean foundTerminator = FALSE;
  105.  
  106.     if (source!=NULL && availableReadBytes>0)
  107.     {
  108.         // Read sink until null terminator found or no bytes to read.
  109.         while (!foundTerminator && availableReadBytes)
  110.         {
  111.             long i;
  112.             // Copy all characters until null-terminator found or all available bytes copied.
  113.             for (i = 0; !foundTerminator && (i < availableReadBytes); ++i)
  114.             {
  115.                 char copyChar = source[i];
  116.                 *destination++ = copyChar; // Note: null-terminator is copied too.
  117.                  if (copyChar == '\0')
  118.                     foundTerminator = TRUE;
  119.             }
  120.     
  121.             // Advance sink position by number of characters processed.
  122.             sink.ReadPeekAdvance(i);
  123.     
  124.             // If null-terminator not found, advance position in sink.
  125.             if (!foundTerminator)
  126.             {
  127.                 totalBytesCopied += availableReadBytes;
  128.                 source = (const char *)sink.ReadPeek(availableReadBytes);
  129.             }
  130.         }
  131.     }
  132.     else
  133.     {
  134.         availableReadBytes = sink.GetReadableBytes();
  135.         while (!foundTerminator && availableReadBytes)
  136.         {
  137.             sink.Read(destination,1);
  138.             --availableReadBytes;
  139.             ++totalBytesCopied;
  140.             foundTerminator = (*destination++ != '\0');
  141.         }
  142.         
  143.     }
  144.     if (!foundTerminator)
  145.         FW_Failure(FW_xReadableStreamFormatter);
  146. }
  147.  
  148. //----------------------------------------------------------------------------------------
  149. // FW_CReadableStreamFormatter::ReadInts
  150. //----------------------------------------------------------------------------------------
  151.  
  152. void FW_CReadableStreamFormatter::ReadInts(FW_CSink& sink,
  153.                                            int* destination,
  154.                                            long count)
  155. {
  156.     Identity(sink, destination, count, sizeof(int));
  157. }
  158.  
  159. //----------------------------------------------------------------------------------------
  160. // FW_CReadableStreamFormatter::ReadUnsignedInts
  161. //----------------------------------------------------------------------------------------
  162.  
  163. void FW_CReadableStreamFormatter::ReadUnsignedInts(FW_CSink& sink,
  164.                                                    unsigned int* destination,
  165.                                                    long count)
  166. {
  167.     Identity(sink, destination, count, sizeof(unsigned int));
  168. }
  169.  
  170. //----------------------------------------------------------------------------------------
  171. // FW_CReadableStreamFormatter::ReadShorts
  172. //----------------------------------------------------------------------------------------
  173.  
  174. void FW_CReadableStreamFormatter::ReadShorts(FW_CSink& sink,
  175.                                              short* destination,
  176.                                              long count)
  177. {
  178.     Identity(sink, destination, count, sizeof(short));
  179. }
  180.  
  181. //----------------------------------------------------------------------------------------
  182. // FW_CReadableStreamFormatter::ReadUnsignedShorts
  183. //----------------------------------------------------------------------------------------
  184.  
  185. void FW_CReadableStreamFormatter::ReadUnsignedShorts(FW_CSink& sink,
  186.                                                      unsigned short* destination,
  187.                                                      long count)
  188. {
  189.     Identity(sink, destination, count, sizeof(unsigned short));
  190. }
  191.  
  192. //----------------------------------------------------------------------------------------
  193. // FW_CReadableStreamFormatter::ReadLongs
  194. //----------------------------------------------------------------------------------------
  195.  
  196. void FW_CReadableStreamFormatter::ReadLongs(FW_CSink& sink,
  197.                                             long* destination,
  198.                                             long count)
  199. {
  200.     Identity(sink, destination, count, sizeof(long));
  201. }
  202.     
  203. //----------------------------------------------------------------------------------------
  204. // FW_CReadableStreamFormatter::ReadUnsignedLongs
  205. //----------------------------------------------------------------------------------------
  206.  
  207. void FW_CReadableStreamFormatter::ReadUnsignedLongs(FW_CSink& sink,
  208.                                                     unsigned long* destination,
  209.                                                     long count)
  210. {
  211.     Identity(sink, destination, count, sizeof(unsigned long));
  212. }
  213.  
  214. //----------------------------------------------------------------------------------------
  215. // FW_CReadableStreamFormatter::ReadFloats
  216. //----------------------------------------------------------------------------------------
  217.  
  218. void FW_CReadableStreamFormatter::ReadFloats(FW_CSink& sink,
  219.                                              float* destination,
  220.                                              long count)
  221. {
  222.     Identity(sink, destination, count, sizeof(float));
  223. }
  224.  
  225. //----------------------------------------------------------------------------------------
  226. // FW_CReadableStreamFormatter::ReadDoubles
  227. //----------------------------------------------------------------------------------------
  228.  
  229. void FW_CReadableStreamFormatter::ReadDoubles(FW_CSink& sink,
  230.                                               double* destination,
  231.                                               long count)
  232. {
  233.     Identity(sink, destination, count, sizeof(double));
  234. }
  235.  
  236. #ifdef FW_COMPILER_SUPPORTS_LONG_DOUBLE
  237. //----------------------------------------------------------------------------------------
  238. // FW_CReadableStreamFormatter::ReadLongDoubles
  239. //----------------------------------------------------------------------------------------
  240.  
  241. void FW_CReadableStreamFormatter::ReadLongDoubles(FW_CSink& sink,
  242.                                                   long double* destination,
  243.                                                   long count)
  244. {
  245.     Identity(sink, destination, count, sizeof(long double));
  246. }
  247. #endif
  248.  
  249. //----------------------------------------------------------------------------------------
  250. // FW_CReadableStreamFormatter::Identity
  251. //----------------------------------------------------------------------------------------
  252.  
  253. void FW_CReadableStreamFormatter::Identity(FW_CSink& sink,
  254.                                            void* destination,
  255.                                            long count,
  256.                                            long itemSize)
  257. {
  258.     char* currentDestination = (char*) destination;
  259.     long totalBytesToRead = count * itemSize;
  260.     long bytesLeftToRead = totalBytesToRead;
  261.     long bytesAvailable = sink.GetReadableBytes();
  262.     long bytesToReadThisTime = FW_Minimum(bytesLeftToRead, bytesAvailable);
  263.  
  264.     while (bytesToReadThisTime)
  265.     {
  266.         sink.Read(currentDestination, bytesToReadThisTime);
  267.         currentDestination += bytesToReadThisTime;
  268.         bytesLeftToRead -= bytesToReadThisTime;
  269.         bytesAvailable = sink.GetReadableBytes();
  270.         bytesToReadThisTime = FW_Minimum(bytesLeftToRead, bytesAvailable);
  271.     }
  272.  
  273.     if (bytesLeftToRead)
  274.         FW_Failure(FW_xReadableStreamFormatter);
  275. }
  276.  
  277.  
  278. //========================================================================================
  279. //    CLASS FW_CWritableStreamFormatter
  280. //========================================================================================
  281.  
  282. //----------------------------------------------------------------------------------------
  283. // FW_CWritableStreamFormatter::FW_CWritableStreamFormatter
  284. //----------------------------------------------------------------------------------------
  285.  
  286. FW_CWritableStreamFormatter::FW_CWritableStreamFormatter()
  287. {
  288. }
  289.  
  290. //----------------------------------------------------------------------------------------
  291. // FW_CWritableStreamFormatter::~FW_CWritableStreamFormatter
  292. //----------------------------------------------------------------------------------------
  293.  
  294. FW_CWritableStreamFormatter::~FW_CWritableStreamFormatter()
  295. {
  296. }
  297.  
  298. //----------------------------------------------------------------------------------------
  299. // FW_CWritableStreamFormatter::WriteBytes
  300. //----------------------------------------------------------------------------------------
  301.  
  302. void FW_CWritableStreamFormatter::WriteBytes(FW_CSink& sink,
  303.                                              const void* source,
  304.                                              long count)
  305. {
  306.     Identity(sink, source, count, 1);
  307. }
  308.  
  309. //----------------------------------------------------------------------------------------
  310. // FW_CWritableStreamFormatter::WriteChars
  311. //----------------------------------------------------------------------------------------
  312.  
  313. void FW_CWritableStreamFormatter::WriteChars(FW_CSink& sink,
  314.                                              const char* source,
  315.                                              long count)
  316. {
  317.     Identity(sink, source, count, sizeof(char));
  318. }
  319.  
  320. //----------------------------------------------------------------------------------------
  321. // FW_CWritableStreamFormatter::WriteSignedChars
  322. //----------------------------------------------------------------------------------------
  323.  
  324. void FW_CWritableStreamFormatter::WriteSignedChars(FW_CSink& sink,
  325.                                                    const signed char* source,
  326.                                                    long count)
  327. {
  328.     Identity(sink, source, count, sizeof(signed char));
  329. }
  330.  
  331. //----------------------------------------------------------------------------------------
  332. // FW_CWritableStreamFormatter::WriteUnsignedChars
  333. //----------------------------------------------------------------------------------------
  334.  
  335. void FW_CWritableStreamFormatter::WriteUnsignedChars(FW_CSink& sink,
  336.                                                      const unsigned char* source,
  337.                                                      long count)
  338. {
  339.     Identity(sink, source, count, sizeof(unsigned char));
  340. }
  341.  
  342. //----------------------------------------------------------------------------------------
  343. // FW_CWritableStreamFormatter::WriteNullTerminatedString
  344. //----------------------------------------------------------------------------------------
  345.  
  346. void FW_CWritableStreamFormatter::WriteNullTerminatedString(FW_CSink& sink,
  347.                                                             const char* source)
  348. {
  349.     Identity(sink, source, FW_PrimitiveStringLength(source) + 1, 1);
  350. }
  351.  
  352. //----------------------------------------------------------------------------------------
  353. // FW_CWritableStreamFormatter::WriteInts
  354. //----------------------------------------------------------------------------------------
  355.  
  356. void FW_CWritableStreamFormatter::WriteInts(FW_CSink& sink,
  357.                                             const int* source,
  358.                                             long count)
  359. {
  360.     Identity(sink, source, count, sizeof(int));
  361. }
  362.     
  363. //----------------------------------------------------------------------------------------
  364. // FW_CWritableStreamFormatter::WriteUnsignedInts
  365. //----------------------------------------------------------------------------------------
  366.  
  367. void FW_CWritableStreamFormatter::WriteUnsignedInts(FW_CSink& sink,
  368.                                                     const unsigned int* source,
  369.                                                     long count)
  370. {
  371.     Identity(sink, source, count, sizeof(unsigned int));
  372. }
  373.  
  374. //----------------------------------------------------------------------------------------
  375. // FW_CWritableStreamFormatter::WriteShorts
  376. //----------------------------------------------------------------------------------------
  377.  
  378. void FW_CWritableStreamFormatter::WriteShorts(FW_CSink& sink,
  379.                                               const short* source,
  380.                                               long count)
  381. {
  382.     Identity(sink, source, count, sizeof(short));
  383. }
  384.     
  385. //----------------------------------------------------------------------------------------
  386. // FW_CWritableStreamFormatter::WriteUnsignedShorts
  387. //----------------------------------------------------------------------------------------
  388.  
  389. void FW_CWritableStreamFormatter::WriteUnsignedShorts(FW_CSink& sink,
  390.                                                       const unsigned short* source,
  391.                                                       long count)
  392. {
  393.     Identity(sink, source, count, sizeof(unsigned short));
  394. }
  395.  
  396. //----------------------------------------------------------------------------------------
  397. // FW_CWritableStreamFormatter::WriteLongs
  398. //----------------------------------------------------------------------------------------
  399.  
  400. void FW_CWritableStreamFormatter::WriteLongs(FW_CSink& sink,
  401.                                              const long* source,
  402.                                              long count)
  403. {
  404.     Identity(sink, source, count, sizeof(long));
  405. }
  406.  
  407. //----------------------------------------------------------------------------------------
  408. // FW_CWritableStreamFormatter::WriteUnsignedLongs
  409. //----------------------------------------------------------------------------------------
  410.  
  411. void FW_CWritableStreamFormatter::WriteUnsignedLongs(FW_CSink& sink,
  412.                                                      const unsigned long* source,
  413.                                                      long count)
  414. {
  415.     Identity(sink, source, count, sizeof(unsigned long));
  416. }
  417.  
  418. //----------------------------------------------------------------------------------------
  419. // FW_CWritableStreamFormatter::WriteFloats
  420. //----------------------------------------------------------------------------------------
  421.  
  422. void FW_CWritableStreamFormatter::WriteFloats(FW_CSink& sink,
  423.                                               const float* source,
  424.                                               long count)
  425. {
  426.     Identity(sink, source, count, sizeof(float));
  427. }
  428.  
  429. //----------------------------------------------------------------------------------------
  430. // FW_CWritableStreamFormatter::WriteDoubles
  431. //----------------------------------------------------------------------------------------
  432.  
  433. void FW_CWritableStreamFormatter::WriteDoubles(FW_CSink& sink,
  434.                                                const double* source,
  435.                                                long count)
  436. {
  437.     Identity(sink, source, count, sizeof(double));
  438. }
  439.  
  440. #ifdef FW_COMPILER_SUPPORTS_LONG_DOUBLE
  441. //----------------------------------------------------------------------------------------
  442. // FW_CWritableStreamFormatter::WriteLongDoubles
  443. //----------------------------------------------------------------------------------------
  444.  
  445. void FW_CWritableStreamFormatter::WriteLongDoubles(FW_CSink& sink,
  446.                                                    const long double* source,
  447.                                                    long count)
  448. {
  449.     Identity(sink, source, count, sizeof(long double));
  450. }
  451. #endif
  452.  
  453. //----------------------------------------------------------------------------------------
  454. // FW_CWritableStreamFormatter::Identity
  455. //----------------------------------------------------------------------------------------
  456.  
  457. void FW_CWritableStreamFormatter::Identity(FW_CSink& sink,
  458.                                            const void* source,
  459.                                            long count,
  460.                                            long itemSize)
  461. {
  462.     const char* currentSource = (const char*) source;
  463.     long totalBytesToWrite = count * itemSize;
  464.     long bytesLeftToWrite = totalBytesToWrite;
  465.     long bytesAvailable = sink.GetWritableBytes();
  466.     long bytesToWriteThisTime = FW_Minimum(bytesLeftToWrite, bytesAvailable);
  467.  
  468.     while (bytesToWriteThisTime)
  469.     {
  470.         sink.Write(currentSource, bytesToWriteThisTime);
  471.         currentSource += bytesToWriteThisTime;
  472.         bytesLeftToWrite -= bytesToWriteThisTime;
  473.         bytesAvailable = sink.GetWritableBytes();
  474.         bytesToWriteThisTime = FW_Minimum(bytesLeftToWrite, bytesAvailable);
  475.     }
  476.  
  477.     if (bytesLeftToWrite)
  478.         FW_Failure(FW_xWritableStreamFormatter);
  479. }
  480.  
  481.  
  482. //======================================================================================
  483. //    class FW_CByteSwapper
  484. //======================================================================================
  485.  
  486. //----------------------------------------------------------------------------------------
  487. // FW_CByteSwapper::SwapShort
  488. //----------------------------------------------------------------------------------------
  489.  
  490. void FW_CByteSwapper::SwapShort(void *aShort)
  491. {
  492.     char* s = (char*)aShort;
  493.     char c = s[0];
  494.     s[0] = s[1];
  495.     s[1] = c;
  496. }
  497.  
  498. //----------------------------------------------------------------------------------------
  499. // FW_CByteSwapper::SwapLong
  500. //----------------------------------------------------------------------------------------
  501.  
  502. void FW_CByteSwapper::SwapLong(void *aLong)
  503. {
  504.     char* s = (char*)aLong;
  505.     char c = s[0];
  506.     s[0] = s[3];
  507.     s[3] = c;
  508.     c = s[1];
  509.     s[1] = s[2];
  510.     s[2] = c;
  511. }
  512.  
  513. //======================================================================================
  514. //    class FW_CReadableSwapBytesFormatter
  515. //======================================================================================
  516.  
  517. //----------------------------------------------------------------------------------------
  518. // FW_CReadableSwapBytesFormatter::FW_CReadableSwapBytesFormatter
  519. //----------------------------------------------------------------------------------------
  520.  
  521. FW_CReadableSwapBytesFormatter::FW_CReadableSwapBytesFormatter()
  522. {
  523. }
  524.  
  525. //----------------------------------------------------------------------------------------
  526. // FW_CReadableSwapBytesFormatter::~FW_CReadableSwapBytesFormatter
  527. //----------------------------------------------------------------------------------------
  528.  
  529. FW_CReadableSwapBytesFormatter::~FW_CReadableSwapBytesFormatter()
  530. {
  531. }
  532.  
  533. //----------------------------------------------------------------------------------------
  534. // FW_CReadableSwapBytesFormatter::ReadInts
  535. //----------------------------------------------------------------------------------------
  536.  
  537. void FW_CReadableSwapBytesFormatter::ReadInts(FW_CSink& sink,
  538.                                               int* destination,
  539.                                               long count)
  540. {
  541. #if FW_FOUR_BYTE_INTS
  542.     ReadLongs(sink, (long*)destination, count);
  543. #else
  544.     ReadShorts(sink, (short*)destination, count);
  545. #endif
  546. }
  547.  
  548. //----------------------------------------------------------------------------------------
  549. // FW_CReadableSwapBytesFormatter::ReadUnsignedInts
  550. //----------------------------------------------------------------------------------------
  551.  
  552. void FW_CReadableSwapBytesFormatter::ReadUnsignedInts(FW_CSink& sink,
  553.                                                       unsigned int* destination,
  554.                                                       long count)
  555. {
  556.     ReadInts(sink, (int*)destination, count);
  557. }
  558.  
  559. //----------------------------------------------------------------------------------------
  560. // FW_CReadableSwapBytesFormatter::ReadShorts
  561. //----------------------------------------------------------------------------------------
  562.  
  563. void FW_CReadableSwapBytesFormatter::ReadShorts(FW_CSink& sink,
  564.                                                 short* destination,
  565.                                                 long count)
  566. {
  567.     FW_CReadableStreamFormatter::ReadShorts(sink, destination, count);
  568.  
  569.     short* p = destination;
  570.     while (p < destination + count)
  571.     {
  572.         FW_CByteSwapper::SwapShort(p);
  573.         p++;
  574.     }
  575. }
  576.  
  577. //----------------------------------------------------------------------------------------
  578. // FW_CReadableSwapBytesFormatter::ReadUnsignedShorts
  579. //----------------------------------------------------------------------------------------
  580.  
  581. void FW_CReadableSwapBytesFormatter::ReadUnsignedShorts(FW_CSink& sink,
  582.                                                         unsigned short* destination,
  583.                                                         long count)
  584. {
  585.     ReadShorts(sink, (short*)destination, count);
  586. }
  587.  
  588. //----------------------------------------------------------------------------------------
  589. // FW_CReadableSwapBytesFormatter::ReadLongs
  590. //----------------------------------------------------------------------------------------
  591.  
  592. void FW_CReadableSwapBytesFormatter::ReadLongs(FW_CSink& sink,
  593.                                                long* destination,
  594.                                                long count)
  595. {
  596.     FW_CReadableStreamFormatter::ReadLongs(sink, destination, count);
  597.  
  598.     long* p = destination;
  599.     while (p < destination + count)
  600.     {
  601.         FW_CByteSwapper::SwapLong(p);
  602.         p++;
  603.     }
  604. }
  605.  
  606. //----------------------------------------------------------------------------------------
  607. // FW_CReadableSwapBytesFormatter::ReadUnsignedLongs
  608. //----------------------------------------------------------------------------------------
  609.  
  610. void FW_CReadableSwapBytesFormatter::ReadUnsignedLongs(FW_CSink& sink,
  611.                                                        unsigned long* destination,
  612.                                                        long count)
  613. {
  614.     ReadLongs(sink, (long*)destination, count);
  615. }
  616.  
  617. //======================================================================================
  618. //    class FW_CWritableSwapBytesFormatter
  619. //======================================================================================
  620.  
  621. //----------------------------------------------------------------------------------------
  622. // FW_CWritableSwapBytesFormatter::ReadLongs
  623. //----------------------------------------------------------------------------------------
  624.  
  625. FW_CWritableSwapBytesFormatter::FW_CWritableSwapBytesFormatter()
  626. {
  627. }
  628.  
  629. //----------------------------------------------------------------------------------------
  630. // FW_CWritableSwapBytesFormatter::ReadLongs
  631. //----------------------------------------------------------------------------------------
  632.  
  633. FW_CWritableSwapBytesFormatter::~FW_CWritableSwapBytesFormatter()
  634. {
  635. }
  636.  
  637. //----------------------------------------------------------------------------------------
  638. // FW_CWritableSwapBytesFormatter::WriteInts
  639. //----------------------------------------------------------------------------------------
  640.  
  641. void FW_CWritableSwapBytesFormatter::WriteInts(FW_CSink& sink,
  642.                                                const int* source,
  643.                                                long count)
  644. {
  645. #if FW_FOUR_BYTE_INTS
  646.     WriteLongs(sink, (const long*)source, count);
  647. #else
  648.     WriteShorts(sink, (const short*)source, count);
  649. #endif
  650. }
  651.  
  652. //----------------------------------------------------------------------------------------
  653. // FW_CWritableSwapBytesFormatter::WriteUnsignedInts
  654. //----------------------------------------------------------------------------------------
  655.  
  656. void FW_CWritableSwapBytesFormatter::WriteUnsignedInts(FW_CSink& sink,
  657.                                                        const unsigned int* source,
  658.                                                        long count)
  659. {
  660.     WriteInts(sink, (const int *)source, count);
  661. }
  662.  
  663. //----------------------------------------------------------------------------------------
  664. // FW_CWritableSwapBytesFormatter::WriteShorts
  665. //----------------------------------------------------------------------------------------
  666.  
  667. void FW_CWritableSwapBytesFormatter::WriteShorts(FW_CSink& sink,
  668.                                                  const short* source,
  669.                                                  long count)
  670. {
  671.     while (count-- != 0)
  672.     {
  673.         short aShort = *source++;
  674.         FW_CByteSwapper::SwapShort(&aShort);
  675.         Identity(sink, &aShort, 1, sizeof(short));
  676.     }
  677. }
  678.  
  679. //----------------------------------------------------------------------------------------
  680. // FW_CWritableSwapBytesFormatter::WriteUnsignedShorts
  681. //----------------------------------------------------------------------------------------
  682.  
  683. void FW_CWritableSwapBytesFormatter::WriteUnsignedShorts(FW_CSink& sink,
  684.                                                          const unsigned short* source,
  685.                                                          long count)
  686. {
  687.     WriteShorts(sink, (const short *)source, count);
  688. }
  689.  
  690. //----------------------------------------------------------------------------------------
  691. // FW_CWritableSwapBytesFormatter::WriteLongs
  692. //----------------------------------------------------------------------------------------
  693.  
  694. void FW_CWritableSwapBytesFormatter::WriteLongs(FW_CSink& sink,
  695.                                                 const long* source,
  696.                                                 long count)
  697. {
  698.     while (count-- != 0)
  699.     {
  700.         long aLong = *source++;
  701.         FW_CByteSwapper::SwapLong(&aLong);
  702.         Identity(sink, &aLong, 1, sizeof(long));
  703.     }
  704. }
  705.  
  706. //----------------------------------------------------------------------------------------
  707. // FW_CWritableSwapBytesFormatter::WriteUnsignedLongs
  708. //----------------------------------------------------------------------------------------
  709.  
  710. void FW_CWritableSwapBytesFormatter::WriteUnsignedLongs(FW_CSink& sink,
  711.                                                         const unsigned long* source,
  712.                                                         long count)
  713. {
  714.     WriteLongs(sink, (const long *)source, count);
  715. }
  716.